package com.wkedu.repair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wkedu.repair.dao.RepairTeacherMapper;
import com.wkedu.repair.dto.RepairTeacherDto;
import com.wkedu.repair.entity.RepairTeacher;
import com.wkedu.repair.service.RepairTeacherService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 港港
 * @version 1.0
 * @date 2021/9/6 3:32 下午
 */
@Service
@Transactional
public class RepairTeacherServiceImpl implements RepairTeacherService {

    @Resource
    private RepairTeacherMapper repairTeacherMapper;

    @Override
    public void add(RepairTeacherDto repairTeacherDto) {
        RepairTeacher repairTeacher = new RepairTeacher();
        repairTeacher.setTeacherId(repairTeacherDto.getTeacherId());
        repairTeacher.setRepairInfo(repairTeacherDto.getRepairInfo());
        repairTeacher.setRepairType(repairTeacherDto.getRepairType());
        repairTeacher.setRepairPath(repairTeacherDto.getRepairPath());

        repairTeacherMapper.insert(repairTeacher);
    }

    @Override
    public List<RepairTeacherDto> listForStudentId(String teacherId) {
        QueryWrapper<RepairTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<RepairTeacher> repairTeachers = repairTeacherMapper.selectList(wrapper);
        if (repairTeachers != null){
            List<RepairTeacherDto> collect = repairTeachers.stream().map(i -> new RepairTeacherDto(
                    i.getRepairInfo(), i.getRepairPath(), i.getRepairType(), i.getTeacherId()
            )).collect(Collectors.toList());
            return collect;
        }else {
            return null;
        }
    }
}
